var cnDayName = [ "周一", "周二", "周三", "周四", "周五", "周六", "周日" ];
function prepareCal( date ) {
	var currYear = date.getFullYear();
	var currMonth = date.getMonth();
	var currDate = date.getDate();
	var dayName = cnDayName[ date.getDay() - 1 ];
	$( "desc" ).innerHTML = currYear + "年" + currMonth + "月" + currDate + "日，" + dayName;

	var firstDay = new Date( currYear, currMonth, 1 ).getDay();
	var days = new Array();
	for( var i = firstDay; i > 0 ; i-- ) {
		date = new Date( currYear, currMonth, 0 - i + 1 );
		days.push( { "date": date, "style": "day pmd" } );
	}
	var length = new Date( currYear, currMonth + 1, 0 ).getDate();
	for( var i = 1; i <= length; i++ ) {
		date = new Date( currYear, currMonth, i );
		if( i == currDate ) {
			days.push( { "date": date, "style": "day crd" } );
		} else if( date.getDay() == 5 || date.getDay() == 6 ) {
			days.push( { "date": date, "style": "day wnd" } );
		} else {
			days.push( { "date": date, "style": "day cmd" } );
		}
	}
	length = 35 - days.length;
	for( var i = 1; i <= length; i++ ) {
		date = new Date( currYear, currMonth + 1, i );
		days.push( { "date": date, "style": "day nmd" } );
	}
	fillCal( days );
}
function fillCal( days ) {
	var table = $( "caltable" ).getElementsByTagName( "tbody" )[ 0 ];
	for( var i = 1; i < 6; i++ ) {
		for( var j = 0; j < 7; j++ ) {
			var cell = table.rows [ i ].cells[ j ];
			//cell.onmouseover = onOver;
			//cell.onmouseout = onOut;
			//cell.onclick = onOver;

			var day = days.shift();
			cell.date = day[ "date" ];
			cell.innerHTML = day[ "date" ].getDate();
			cell.className = day[ "style" ];
		}
	}
}